//
//  StellWeightAndLineTableViewCell.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/22.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "StellWeightAndLineTableViewCell.h"

@interface StellWeightAndLineTableViewCell ()
@property (nonatomic,strong) GLGWLabel * leftTitleLabel;
@property (nonatomic,strong) GLGWView * inputBankgroundView;
@property (nonatomic,strong) GLGWTextField * inputTextField;
@end

@implementation StellWeightAndLineTableViewCell{
    GLGWButton * unitBut;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.leftTitleLabel = [[GLGWLabel alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(15), kHeightProportion_In_iPhoneTriploid(27), kWidthProportion_In_iPhoneTriploid(56), kHeightProportion_In_iPhoneTriploid(20)) theFont:SYSTEMFONT(14) theColor:[UIColor colorWithHexString:@"#666666"] inSuperView:self];
//        [self.leftTitleLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
        //
        self.inputBankgroundView = [[GLGWView alloc] initWithFrame:CGRectMake(kX_With_View(self.leftTitleLabel, 15), kHeightProportion_In_iPhoneTriploid(15), KScreenWidth  - kX_With_View(self.leftTitleLabel, 30), kHeightProportion_In_iPhoneTriploid(44)) inSuperView:self];
        self.inputBankgroundView.layer.borderWidth = 1.0;
        self.inputBankgroundView.layer.borderColor = [UIColor colorWithHexString:@"#CCCCCC"].CGColor;
        self.inputBankgroundView.layer.masksToBounds = YES;
        //
        self.inputTextField = [[GLGWTextField alloc] initTitlePlaceholder:@"" theFont:SYSTEMFONT(14) theTitColor:kColor_Rule_Black inSuperView:self.inputBankgroundView];
        self.inputTextField.textAlignment = NSTextAlignmentRight;
        self.inputTextField.keyboardType = UIKeyboardTypeDecimalPad;
        [self.inputTextField addTarget:self action:@selector(textField1TextEndOnExit:) forControlEvents:UIControlEventEditingDidEnd];
        [self.inputTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.inputBankgroundView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(10));
            make.top.bottom.equalTo(self.inputBankgroundView).offset(0);
            make.right.equalTo(self.inputBankgroundView.mas_right).offset(-kWidthProportion_In_iPhoneTriploid(59));
        }];
        //
        GLGWView * lineView = [[GLGWView alloc] initWithInSuperView:self.inputBankgroundView];
        lineView.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.inputTextField.mas_right).offset(kWidthProportion_In_iPhoneTriploid(15));
            make.centerY.equalTo(self.inputBankgroundView);
            make.width.equalTo(@1);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(20)));
        }];
        //
        unitBut = [[GLGWButton alloc] initWithTitleLableFontType:SYSTEMFONT(14) titleColor:[UIColor colorWithHexString:@"#666666"] inSuperView:self.inputBankgroundView];
        unitBut.title = @"mm";
        unitBut.enabled = NO;
        [unitBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(lineView.mas_right).offset(0);
            make.right.equalTo(self.inputBankgroundView.mas_right).offset(0);
            make.top.bottom.equalTo(self.inputBankgroundView).offset(0);
        }];
        [unitBut addTarget:self action:@selector(puEmum) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

-(void)puEmum{
    if (self.Block_EmumAction) {
        self.Block_EmumAction();
    }
}

-(void)setLeftTitleLabelWidth:(CGFloat)leftTitleLabelWidth{
    _leftTitleLabelWidth = leftTitleLabelWidth;
//    DLog(@"%f",_leftTitleLabelWidth);
    self.leftTitleLabel.width = _leftTitleLabelWidth;
    self.inputBankgroundView.x = kX_With_View(_leftTitleLabel, 15);
    self.inputBankgroundView.width = KScreenWidth  - kX_With_View(self.leftTitleLabel, 30);
}

-(void)setLeftTitStr:(NSString *)leftTitStr{
    _leftTitStr = leftTitStr;
    if ([_leftTitStr containsString:@"("]) {
        NSString *string;
        NSRange range = [_leftTitStr rangeOfString:@"("];//匹配得到的下标
        string = [_leftTitStr substringFromIndex:range.location];
        self.leftTitleLabel.attributedText = [GLGWLabel bllChangeStr:_leftTitStr changewithStr:string changeColoer:[UIColor colorWithHexString:@"#999999"] withFont:SYSTEMFONT(14)];
    }else{
        self.leftTitleLabel.text = _leftTitStr;
    }
    
}

-(void)setIsLastCell:(BOOL)isLastCell{
    _isLastCell = isLastCell;
    if (_isLastCell) {
        if (_type_m == CaiculatorType_Weight) {
            unitBut.title = @"m";
        }else{
            unitBut.title = @"吨";
        }
    }
}

-(void)setCollectionRow:(NSInteger)collectionRow{
    _collectionRow = collectionRow;
    if (_collectionRow == 13 &&(_rowIndex == 0 || _rowIndex == 1)) {
        self.inputTextField.userInteractionEnabled = NO;
        unitBut.enabled = YES;
        unitBut.title = @"";
        unitBut.backgroundColor = kRandomColor;
    }
}

-(void)setRowIndex:(NSInteger)rowIndex{
    _rowIndex = rowIndex;
}

-(void)setCai_model:(StellCaiculatorModel *)cai_model{
    _cai_model = cai_model;
}

-(void)textField1TextEndOnExit:(GLGWTextField *)textField{
    switch (_rowIndex) {
        case 0:{
            _cai_model.listOne = [koString(textField.text) doubleValue];
        }
            break;
        case 1:{
            _cai_model.listTwo = [koString(textField.text) doubleValue];
        }
            break;
        case 2:{
            _cai_model.listThree = [koString(textField.text) doubleValue];
        }
            break;
        case 3:{
            _cai_model.listFour = [koString(textField.text) doubleValue];
        }
            break;
        case 4:{
            _cai_model.listFiver = [koString(textField.text) doubleValue];
        }
            break;
        case 5:{
            _cai_model.listSix = [koString(textField.text) doubleValue];
        }
            break;
        case 6:{
            _cai_model.listSeven = [koString(textField.text) doubleValue];
        }
            break;
            
        default:
            break;
    }
}

-(void)setTextFieldStr:(NSString *)textFieldStr{
    _textFieldStr = textFieldStr;
    self.inputTextField.text = _textFieldStr;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
